

<!DOCTYPE html>
<html lang="zh-CN">

<head><meta name="generator" content="Hexo 3.9.0">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>2.2从教务系统查询成绩并计算绩点——山东建筑大学为例 - 杨云召 | 博客</title>
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
  <meta name="google" content="notranslate">

  
  
  <meta name="description" content="
前两天面试时被问到绩点是多少，但学校教务系统不提供绩..."> 
  
  <meta name="author" content="杨云召（Flywith24）"> 

  
    <link rel="icon" href="/images/icons/favicon-16x16.png" type="image/png" sizes="16x16">
  
  
    <link rel="icon" href="/images/icons/favicon-32x32.png" type="image/png" sizes="32x32">
  
  
    <link rel="apple-touch-icon" href="/images/icons/apple-touch-icon.png" sizes="180x180">
  
  
    <meta rel="mask-icon" href="/images/icons/stun-logo.svg" color="#333333">
  
  
    <meta rel="msapplication-TileImage" content="/images/icons/favicon-144x144.png">
    <meta rel="msapplication-TileColor" content="#000000">
  

  <link rel="stylesheet" href="/css/style.css">

  
  <link rel="stylesheet" href="//at.alicdn.com/t/font_1445822_hhodbqn7tit.css">
  

  
  
  <link rel="stylesheet" href="https://cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.min.css">
  

  
  
  <link rel="stylesheet" href="https://cdn.bootcss.com/highlight.js/9.18.1/styles/xcode.min.css">
  

  <script>
    var CONFIG = window.CONFIG || {};
    var ZHAOO = window.ZHAOO || {};
    CONFIG = {
      isHome: false,
      fancybox: true,
      pjax: false,
      lazyload: {
        enable: true,
        loadingImage: '/images/theme/loading.gif',
      },
      donate: {
        enable: true,
        alipay: 'https://gitee.com/flywith24/Album/raw/master/img/20201015113301.jpg',
        wechat: 'https://gitee.com/flywith24/Album/raw/master/img/20201015112814.png'
      },
      motto: {
        api: '',
        default: '不人云亦云，只求接近真相.'
      },
      galleries: {
        enable: true
      },
      fab: {
        enable: true,
        alwaysShow: false
      },
      carrier: {
        enable: true
      },
      daovoice: {
        enable: true
      }
    }
  </script>

  

  
</head></html>
<body class="lock-screen">
  <div class="loading"></div>
  


<nav class="navbar">
  <div class="left"></div>
  <div class="center">2.2从教务系统查询成绩并计算绩点——山东建筑大学为例</div>
  <div class="right">
    <i class="iconfont iconmenu j-navbar-menu"></i>
  </div>
</nav>

  <nav class="menu">
  <div class="menu-wrap">
    <div class="menu-close">
      <i class="iconfont iconbaseline-close-px"></i>
    </div>
    <ul class="menu-content">
      
      
      
      
      <li class="menu-item"><a href="/ " class="underline"> 首页</a></li>
      
      
      
      
      <li class="menu-item"><a href="/archives " class="underline"> 归档</a></li>
      
      
      
      
      <li class="menu-item"><a href="/tags " class="underline"> 标签</a></li>
      
      
      
      
      <li class="menu-item"><a href="/categories " class="underline"> 分类</a></li>
      
      
      
      
      <li class="menu-item"><a href="/about " class="underline"> 关于</a></li>
      
    </ul>
    <div class="menu-copyright"><p>Copyright© 2017 - 2020 ❤️ Flywith24</p></div>
  </div>
</nav>
  <main id="main">
  <div class="container" id="container">
    <article class="article">
  <div class="wrap">
    <section class="head">
  <img   class="lazyload" data-original="https://gitee.com/flywith24/Album/raw/master/img/20201015085822.png" src=""  draggable="false">
  <div class="head-mask">
    <h1 class="head-title">2.2从教务系统查询成绩并计算绩点——山东建筑大学为例</h1>
    <div class="head-info">
      <span class="post-info-item"><i class="iconfont iconcalendar"></i>六月 18, 2017</span
        class="post-info-item">
      
      <span class="post-info-item"><i class="iconfont iconfont-size"></i>6064</span>
    </div>
  </div>
</section>
    <section class="main">
      <section class="content">
        <h3 id="1-准备"><a href="#1-准备" class="headerlink" title="1. 准备"></a>1. 准备</h3><p>HttpFox插件，是一款http协议分析插件，分析页面请求和响应的时间、内容、以及浏览器用到的COOKIE等。是火狐浏览器的插件。谷歌浏览器和Safari都有自带的分析工具，可是感觉太复杂，没有这款好用。不过火狐浏览器对学校的教务系统兼容性不是很好，我还下载了IE tab插件。<br><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-79a8f42d306c605c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="插件的安装"></p>
<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-fdddcc6520d47f18.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt><br>可以非常直观的查看相应的信息。<br>点击start是开始检测，点击stop暂停检测，点击clear清除内容。</p>
<h3 id="2-探究过程"><a href="#2-探究过程" class="headerlink" title="2. 探究过程"></a>2. 探究过程</h3><p>下面就去山东建筑大学官网登录到数字校园综合信息门户，看一看在登录的时候，到底发送了那些信息。<br>先来到登录页面，把httpfox打开，clear之后，点击start开启检测：</p>
<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-0a6c714e2c2ff3a8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="开启检测"><br>输入完账号密码，确保httpfox处于开启状态，然后点击登录。<br>这个时候可以看到，httpfox检测到了好多信息：<br><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-d757be497cda18ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="捕捉到的信息"></p>
<p>那么我们来分析一下这些数据</p>
<p>看起来红框里的两条数据比较有意思，先看看这个post</p>
<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-f72b7d8e3375dafc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="post数据"></p>
<p>PostData中我们看到了比较熟悉的词，username和password，学过java web的我们很清楚这段数据的含义，点击登录后将这用户名和你们提交到服务器比对。<br><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-2a025613cb9cd840.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="重定向到这里"></p>
<p>可以看到这里使用get的方式在链接上以?的方式显示的加上了参数，跳转到信息门户。<br>我们的post的数据就发送到了这个地址</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs undefined">http://urpe.sdjzu.edu.cn/loginPortalUrlForIndexLogin.portal<br></code></pre></td></tr></table></figure>

<p>需要的post数据是用户名密码，也就是说我们需要输入这两种数据来模拟登录过程。</p>
<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-40ea67af08eb6ab1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="进入到教务系统"></p>
<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-c30fa7de450e5621.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="点击成绩查询"><br>进入教务系统后点击成绩查询，我们看到请求的地址为</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><code class="hljs undefined">http://jwfw1.sdjzu.edu.cn/ssfw/jwnavmenu.do?menuItemWid=1E057E24ABAB4CAFE0540010E0235690<br></code></pre></td></tr></table></figure>

<p>我们整理一下整个过程的思路。</p>
<ol>
<li>POST学号和密码—&gt;然后返回cookie的值</li>
<li>发送cookie给服务器—&gt;返回页面信息。</li>
<li>获取到成绩页面的数据，用正则表达式将成绩和学分单独取出并计算加权平均数。</li>
</ol>
<p>ok，理顺思路后剩下的就只有编码问题了。</p>
<h3 id="3-实验"><a href="#3-实验" class="headerlink" title="3. 实验"></a>3. 实验</h3><p>我们先来实验下是否能够获得查询成绩界面的源码</p>
<p>我们先准备一个POST的数据，再准备一个cookie的接收，然后写出源码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><code class="hljs undefined"># coding=utf-8<br>import urllib<br>import urllib2<br>import cookielib<br><br>cookie = cookielib.CookieJar()<br>opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))<br><br># 需要的POST数据<br>postdata = urllib.urlencode(&#123;<br>    &apos;userName&apos;: &apos;20140216064&apos;,<br>    &apos;password&apos;: &apos;*********&apos;<br>&#125;)<br># 自定义一个请求<br>req1 = urllib2.Request(<br>    url=&apos;http://urpe.sdjzu.edu.cn/loginPortalUrlForIndexLogin.portal&apos;,<br>    data=postdata<br>)<br><br>req2 = urllib2.Request(<br>    url=&apos;http://jwfw1.sdjzu.edu.cn/ssfw/jwnavmenu.do?menuItemWid=1E057E24ABAB4CAFE0540010E0235690&apos;<br>)<br><br># 访问登录链接<br>opener.open(req1)<br>result = opener.open(req2)<br># 打印返回的内容<br>print result.read()<br></code></pre></td></tr></table></figure>

<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-c2476106a0e29a70.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="运行结果"></p>
<p>很棒呦，看来跟我们预期的一样。</p>
<h3 id="4-整理数据"><a href="#4-整理数据" class="headerlink" title="4. 整理数据"></a>4. 整理数据</h3><blockquote>
<p>获得了成绩查询界面的源码后我们需要将数据进行整理，获得我们想要的数据，课程名称，学分，成绩。</p>
</blockquote>
<p>将网页源码贴到Sublime Text中，方便我们查看源码</p>
<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-480626d6803e99fb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="分析源码"><br><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-6a978cc4d4c27ba1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="分析源码"><br>通过查看源码我们看到从这个<div>开始到3640行都是关于成绩的代码，而成绩是存放在这个table标签下。<br><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-b1573f6441632f38.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="需要提取的信息"><br>红色框中分别为课程名，学分，以及成绩。这些是我们需要抽取出来的数据。<br>看到这里竟然有意外收获！注意黄色框被注释的部分，看来学校的教务系统有计算绩点的功能的，不知由于何种原因不用呢？</div></p>
<p>这里是这段程序中最困难的部分，我也踩了很多坑。我参照的博客是使用正则表达式来抽取想要的信息的，但我对正则表达式掌握的并不好，弄了好久也没写出合适的表达式，于是我果断放弃了使用正则表达式，采用BeautifulSoup来进行信息的筛选。<br><a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/index.zh.html" target="_blank" rel="noopener">BeautifulSoup用法参考</a></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs undefined"># 将内容从页面源码中提取出来<br>   def deal_data(self, myPage):<br><br>       soup = BeautifulSoup(myPage)<br><br>       # 从title属性为有效成绩的标签中获取所有class属性为t_con的TAG(tr标签)<br>       trs = soup.find(attrs=&#123;&quot;title&quot;: &quot;有效成绩&quot;&#125;).findAll(attrs=&#123;&quot;class&quot;: &quot;t_con&quot;&#125;)<br><br>       # 从tr标签中的td标签中获取需要的信息。下标为3，7，8的分别为课程名，学分，成绩<br>       for tr in trs:<br>           for index, td in enumerate(tr.findAll(&apos;td&apos;)):  # enumerate能在for循环中使用下标<br><br>               if index == 3:<br>                   print td.text<br>               elif index == 7:<br>                   self.weights.append(td.text.encode(&apos;utf8&apos;))<br>                   print td.text<br>               elif index == 8:<br>                   self.points.append(td.text.encode(&apos;utf8&apos;))<br>                   print td.text<br><br>           print<br></code></pre></td></tr></table></figure>

<p>整个逻辑我简单说一下，我觉得还可以改进。<br>首先查找title属性为”有效成绩“的标签，通过上文的截图我们可以知道这是那个div标签，之后在该div标签中定位class为t_con的tr标签。你也许会问为什么不直接定位到tr标签，因为后面的网页代码中还存在class 为t_con的tr标签，但不是我们需要的成绩。然后在每个tr标签下抽取下标为3，7，8的标签，这里我是把它存到数组里了。<br>接下来就清晰了，先打印成绩信息，然后计算绩点。</p>
<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-f6d0aff398d0089a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="运行截图"></p>
<p><img class="lazyload" data-original="http://upload-images.jianshu.io/upload_images/3155702-3d48f5287d16407e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" src="/2017/06/18/2-2-grade/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg==" alt="运行截图"><br>学渣一个，绩点低请忽略。</p>
<p>源码</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><code class="hljs undefined"># encoding=utf8<br>import urllib<br>import urllib2<br>import cookielib<br>import re<br>import string<br>from BeautifulSoup import BeautifulSoup<br>import sys<br><br>reload(sys)<br>sys.setdefaultencoding(&apos;utf8&apos;)<br><br><br>class SDJZU_Crawler:<br>    # 声明相关的属性<br>    def __init__(self):<br><br>        self.loginUrl = &apos;http://urpe.sdjzu.edu.cn/loginPortalUrlForIndexLogin.portal&apos;  # 登录的url<br>        self.resultUrl = &apos;http://jwfw1.sdjzu.edu.cn/ssfw/jwnavmenu.do?menuItemWid=1E057E24ABAB4CAFE0540010E0235690&apos;  # 查询成绩的url<br>        self.cookieJar = cookielib.CookieJar()  # 初始化一个CookieJar来处理Cookie的信息<br>        self.postdata = urllib.urlencode(&#123;&apos;userName&apos;: &apos;&apos;, &apos;password&apos;: &apos;&apos;&#125;)  # 登录需要POST的数据<br>        self.weights = []  # 存储权重，也就是学分<br>        self.points = []  # 存储分数，也就是成绩<br>        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookieJar))<br><br>    def sdjzu_init(self):<br>        username = raw_input(&apos;请输入学号:&apos;)  # 这里不要用input，二者区别请自行查询<br>        password = raw_input(&apos;请输入密码:&apos;)<br>        self.postdata = urllib.urlencode(&#123;&apos;userName&apos;: username, &apos;password&apos;: password&#125;)  # 将用户名密码加入到POST中<br>        # 初始化链接并且获取cookie<br>        myRequest = urllib2.Request(url=self.loginUrl, data=self.postdata)  # 自定义一个请求<br>        result = self.opener.open(myRequest)  # 访问登录页面，获取到必须的cookie的值<br>        result = self.opener.open(self.resultUrl)  # 访问成绩页面，获得成绩的数据<br>        self.deal_data(result.read())<br>        self.calculate_gpa()<br><br>    # 将内容从页面源码中提取出来<br>    def deal_data(self, myPage):<br><br>        soup = BeautifulSoup(myPage)<br><br>        # 从title属性为有效成绩的标签中获取所有class属性为t_con的TAG(tr标签)<br>        trs = soup.find(attrs=&#123;&quot;title&quot;: &quot;有效成绩&quot;&#125;).findAll(attrs=&#123;&quot;class&quot;: &quot;t_con&quot;&#125;)<br><br>        # 从tr标签中的td标签中获取需要的信息。下标为3，7，8的分别为课程名，学分，成绩<br>        for tr in trs:<br>            for index, td in enumerate(tr.findAll(&apos;td&apos;)):  # enumerate能在for循环中使用下标<br><br>                if index == 3:<br>                    print td.text<br>                elif index == 7:<br>                    self.weights.append(td.text.encode(&apos;utf8&apos;))<br>                    print td.text<br>                elif index == 8:<br>                    self.points.append(td.text.encode(&apos;utf8&apos;))<br>                    print td.text<br><br>            print<br><br>    # 计算绩点，如果成绩还没出来，就不算该成绩，<br>    def calculate_gpa(self):<br>        point = 0.0  # 成绩<br>        weight = 0.0  # 学分<br>        for i in range(len(self.points)):<br>            if self.points[i].isdigit() and (self.weights[i] != 0):<br>                point += string.atof(self.points[i]) * string.atof(self.weights[i])  # 成绩*学分累加求和<br>                weight += string.atof(self.weights[i])  # 学分累加求和<br><br>        print &quot;绩点为：&quot;<br>        print point / weight  # 输出绩点 值成绩*学分累加求和 / 学分累加求和<br><br><br># 调用<br>mySpider = SDJZU_Crawler()<br>mySpider.sdjzu_init()<br></code></pre></td></tr></table></figure>

<p><a href="https://github.com/Flywith24" target="_blank" rel="noopener">我的github地址</a></p>
      </section>
      <section class="extra">
        
        <ul class="copyright">
  
  <li><strong>本文作者：</strong>杨云召（Flywith24）</li>
  <li><strong>本文链接：</strong><a href="https://flywith24.gitee.io/2017/06/18/2-2-grade/index.html">https://flywith24.gitee.io/2017/06/18/2-2-grade/index.html</a></li>
  <li><strong>版权声明：</strong>本博客所有文章均采用<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh"
      rel="external nofollow" target="_blank"> BY-NC-SA </a>许可协议，转载请注明出处！</li>
  
</ul>
        
        
        <section class="donate">
  <div class="qrcode">
    <img   class="lazyload" data-original="https://gitee.com/flywith24/Album/raw/master/img/20201015113301.jpg" src="" >
  </div>
  <div class="icon">
    <a href="javascript:;" id="alipay"><i class="iconfont iconalipay"></i></a>
    <a href="javascript:;" id="wechat"><i class="iconfont iconwechat-fill"></i></a>
  </div>
</section>
        
        
  <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/">python</a></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/爬虫/">爬虫</a></li></ul>

        
<nav class="nav">
  
    <a href="/2017/07/04/Handler/"><i class="iconfont iconleft"></i>Handler深入分析</a>
  
  
    <a href="/2017/06/18/2-1-first-program/">2.1开始第一个爬虫程序<i class="iconfont iconright"></i></a>
  
</nav>

      </section>
      
      <section class="comments">
  
  <div class="btn" id="comments-btn">查看评论</div>
  
  
<div id="valine"></div>
<script defer src="//unpkg.com/valine/dist/Valine.min.js"></script>
<script>
  window.onload = function () {
    var loadValine = function () {
      new Valine({
        el: '#valine',
        app_id: "SHA3gzCcxFlqaPcGRnX4UgET-gzGzoHsz",
        app_key: "OYo7ITS4AzTvBUvb1yIY8oaf",
        placeholder: "期待你的留言",
        avatar: "mp",
        pageSize: "10",
        lang: "zh-CN",
      });
    }
    if ( true ) {
      $("#comments-btn").on("click", function () {
        $(this).hide();
        loadValine();
      });
    } else {
      loadValine();
    }
  };
</script>

</section>
      
    </section>
  </div>
</article>
  </div>
</main>
  <footer class="footer">
  <div class="footer-social">
    
    
    
    
    
    <a href="tencent://message/?Menu=yes&uin=1032367864 " target="_blank" onMouseOver="this.style.color= '#12B7F5'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  iconQQ "></i>
    </a>
    
    
    
    
    
    <a href="javascript:; " target="_blank" onMouseOver="this.style.color= '#8bc34a'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  iconwechat-fill "></i>
    </a>
    
    
    
    
    
    <a href="https://flywith24.gitee.io/about/ " target="_blank" onMouseOver="this.style.color= '#d32f2f'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  iconheart "></i>
    </a>
    
    
    
    
    
    <a href="https://github.com/Flywith24 " target="_blank" onMouseOver="this.style.color= '#24292E'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  icongithub-fill "></i>
    </a>
    
    
    
    
    
    <a href="mailto:youngyunzhao@163.com " target="_blank" onMouseOver="this.style.color='#FFBE5B'"
      onMouseOut="this.style.color='#33333D'">
      <i class="iconfont footer-social-item  iconmail"></i>
    </a>
    
  </div>
  <div class="footer-copyright"><p>Copyright© 2017 - 2020 ❤️ Flywith24</p></div>
</footer>
  
      <div class="fab fab-plus">
    <i class="iconfont iconplus"></i>
  </div>
  
  <div class="fab fab-daovoice">
    <i class="iconfont iconcomment"></i>
  </div>
  
  <div class="fab fab-up">
    <i class="iconfont iconcaret-up"></i>
  </div>
  
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":150,"height":300},"mobile":{"show":"tfalse"},"log":false});</script></body>

<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>




<script src="https://cdn.bootcdn.net/ajax/libs/jquery.lazyload/1.9.1/jquery.lazyload.min.js"></script>




<script src="https://cdn.bootcss.com/fancybox/3.5.7/jquery.fancybox.min.js"></script>




<script src="/js/utils.js"></script>
<script src="/js/modules.js"></script>
<script src="/js/zui.js"></script>
<script src="/js/script.js"></script>




<script>
  (function (i, s, o, g, r, a, m) {
    i["DaoVoiceObject"] = r;
    i[r] = i[r] || function () {
      (i[r].q = i[r].q || []).push(arguments)
    }, i[r].l = 1 * new Date();
    a = s.createElement(o), m = s.getElementsByTagName(o)[0];
    a.async = 1;
    a.src = g;
    a.charset = "utf-8";
    m.parentNode.insertBefore(a, m)
  })(window, document, "script", ('https:' == document.location.protocol ? 'https:' : 'http:') +
    "//widget.daovoice.io/widget/0f81ff2f.js", "daovoice")
  daovoice('init', {
    app_id: "7785620b"
  }, {
    launcher: {
      disableLauncherIcon: true,
    },
  });
  daovoice('update');
</script>



<script>
  (function () {
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
      bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    } else {
      bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
  })();
</script>


<script>
  var _hmt = _hmt || [];
  (function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?4c204d8bc027a0455b5fc642ac334ca8";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>










</html>